﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynamicViewFormLibrary.Utils
{
    /// <summary>
    /// 文件路径工具类
    /// </summary>
    public static class FilePathUtil
    {
        private static string RTF_WORK_SPACE_PATH = "_workspace";
        private static string RTF_WORK_SPACE_FILTER = ".rtfs";

        public static string DocumentFilePath()
        {
            string dateTime = DateTimeUtil.DateTimeToTimeStamp(DateTime.Now).ToString();
            string dateStamp = DateTimeUtil.DateStampString(DateTime.Now);

            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//获取桌面目录
            string currentDirectory = GetCurrentDirectory();//获取项目根目录

            string fileName = dateTime + ".docx";

            string fileDir = currentDirectory + "\\" + RTF_WORK_SPACE_PATH + "\\" + dateStamp;
            string filePath = fileDir + "\\" + fileName;

            // 创建目录
            DirectoryInfo newDirectory = new DirectoryInfo(fileDir);
            newDirectory.Create();

            return filePath;
        }

        private static string GetCurrentDirectory()
        {
            string fileDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\CHNLEAD\\DTCard";
            if (!Directory.Exists(fileDir))
            { // 创建目录
                DirectoryInfo dir = new DirectoryInfo(fileDir);
                dir.Create();
            }
            return fileDir;
        }

        public static string RTFFilePath()
        {
            string dateTime = DateTimeUtil.DateTimeToTimeStamp(DateTime.Now).ToString();
            string dateStamp = DateTimeUtil.DateStampString(DateTime.Now);

            string currentDirectory = GetCurrentDirectory(); //获取项目根目录

            string fileName = dateTime + ".rtf";

            string fileDir = currentDirectory + "\\" + RTF_WORK_SPACE_PATH + "\\" + dateStamp;
            string filePath = fileDir + "\\" + fileName;

            // 创建目录
            DirectoryInfo newDirectory = new DirectoryInfo(fileDir);
            newDirectory.Create();

            return filePath;
        }

        /// <summary>
        /// RTF Work Space File Path
        /// </summary>
        /// <returns></returns>
        public static string RTFWorkSpaceFilePath(string title)
        {
            string dateTime = DateTimeUtil.DateTimeToTimeStamp(DateTime.Now).ToString();
            string dateStamp = DateTimeUtil.DateStampString(DateTime.Now);

            string currentDirectory = GetCurrentDirectory(); //获取项目根目录

            string fileName = title + RTF_WORK_SPACE_FILTER;

            string fileDir = currentDirectory + "\\" + RTF_WORK_SPACE_PATH + "\\" + dateStamp;
            string filePath = fileDir + "\\" + fileName;

            // 创建目录
            DirectoryInfo newDirectory = new DirectoryInfo(fileDir);
            newDirectory.Create();

            return filePath;
        }
        public static string RTFWorkSpaceRootPath()
        {
            string currentDirectory = GetCurrentDirectory(); //获取项目根目录
            string fileDir = currentDirectory + "\\" + RTF_WORK_SPACE_PATH;

            // 创建目录
            DirectoryInfo newDirectory = new DirectoryInfo(fileDir);
            newDirectory.Create();
            return fileDir;
        }
        /// <summary>
        /// 删除过程文件
        /// </summary>
        /// <param name="path"></param>
        public static bool DeleteFile(string path)
        {
            try
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
